package cn.yunhe.model;

import cn.yunhe.YangLeGeYangApp;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


/**
 * 牌类
 */

public class Brand extends Component {
    private String name;//牌的名称
    private Boolean isGray;//是否置灰
    private Boolean stats;  //是否是不可点击状态,true不可点击,false可点击
    private Image image;//正常图片
    private Image grayImage;//灰色图片
    //x,y左上⻆对的坐标
    private int x;
    private int y;
    //宽高
    private int width = 50;
    private int height = 50;
    private Cell cell;
    //消除框属性
    private EliminateBox eliminateBox = new EliminateBox();

    //构造方法
    public Brand(String name) {
        //给name属性赋值
        this.name = name;
        //给定图⽚的路径，通过该⼯具类加载图⽚
        this.image = Toolkit.getDefaultToolkit().getImage("imgs//" + name + ".png");
        this.grayImage = Toolkit.getDefaultToolkit().getImage("imgs//" + name + "_gray.png");
        this.isGray = false;
        this.stats = false;

        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                Brand brand = (Brand) e.getSource();//获取事件源
                if (brand.stats || brand.isGray || brand.getName().equals("背景草地") ||
                        brand.getName().equals("消除区域")) {
                    return;// 表示的结束⽅法的执⾏，直接返回
                }

                System.out.println("你点击了" + brand.getName());
                //通过⽗容器删除⾃⼰，⼀般树形结构使⽤这种⽅式
                eliminateBox.addSlot(brand);//调⽤消除框⽅法
                //删除数据结构中的数据
                setStats(true);
                cell.setState(0);//⽆牌状态，你必须设置是当前牌所在的单元格
                cell.setBrand(null);
                YangLeGeYangApp.map.compareAll();//每次点击之后都要重新计算⼀下图层的遮盖
                YangLeGeYangApp.transverseLayer.compareAll();//每次点击之后都要重新计算⼀下图层的遮盖
            }
        });

    }



    public void paint(Graphics g) {
        if (this.isGray == true) {
            //绘制灰色图片
            g.drawImage(this.grayImage, this.x, this.y, null);
        } else {
            //绘制彩色图片
            g.drawImage(this.image, this.x, this.y, null);
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getGray() {
        return isGray;
    }

    public void setGray(Boolean gray) {
        isGray = gray;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image getGrayImage() {
        return grayImage;
    }

    public void setGrayImage(Image grayImage) {
        this.grayImage = grayImage;
    }

    public Cell getCell() {
        return cell;
    }

    public void setCell(Cell cell) {
        this.cell = cell;
    }

    public Boolean getStats() {
        return stats;
    }

    public void setStats(Boolean stats) {
        this.stats = stats;
    }
}



